﻿@model Bottle.CommunityForum.Model.UserInfo
@{
    ViewBag.Title = "用户修改";
    Layout = "~/Views/Shared/_FormLayout.cshtml";
}
@if (Model == null)
{

}
else
{
<form class="layui-form">
    <div class="layui-form-item">
        <label for="L_email" class="layui-form-label">用户姓名</label>
        <div class="layui-input-inline">
            <input type="hidden" id="userid" name="userid" value="@Model.userid" />
            <input type="text" id="username" name="username" value="@Model.username" required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="L_pass" class="layui-form-label">用户密码</label>
        <div class="layui-input-inline">
            <input type="text" id="userpwd" name="userpwd" value="@Model.userpwd" required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="L_pass" class="layui-form-label">用户邮箱</label>
        <div class="layui-input-inline">
            <input type="text" id="email" name="email" value="@Model.email" required lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label for="L_pass" class="layui-form-label">角色</label>
        <div class="layui-input-inline">
            @{
                List<Bottle.CommunityForum.Model.RoleInfo> roleList = ViewBag.RoleList;
                foreach (var role in roleList)
                {
                    <input type="checkbox" name="roles" checked="@Model.role.Contains(role)" title="@role.rolename" lay-skin="primary" value="@role.roleid">
                }
               }
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-filter="login" lay-submit>保存</button>
            <button class="layui-btn" lay-filter="close">关闭</button>
        </div>
    </div>
</form>
}

@section scripts{

    <script>
        layui.config({
            base: "~/Content/res/mods/"
        }).use(['layer', 'form'], function () {
            var layer = layui.layer,
                form = layui.form,
                $ = layui.jquery

            form.on('submit(login)', function (data) {
                var arr = new Array();
                $("input:checkbox[name=roles]:checked").each(function () {
                    arr.push($(this).val());
                });
                data.field.roles = arr.join(",");
                $.post('@Url.Action("UserEdit")', data.field, function (data) {
                    if (data.code == 0) {
                        layer.alert(data.msg);
                    }
                    else {
                        layer.alert(data.msg);
                    }
                }, 'json')
                return false;
            })
        });
    </script>
}
